package com.voice.core.message;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.util.DigestUtils;

@Data
public abstract class AbstractMessage {

    private String topic;
    private String deviceKey;
    private String userId;

    public AbstractMessage(String userId, String deviceKey) {
        this.deviceKey = deviceKey;
        this.userId = userId;
    }

    public String toString(){
        return JSONObject.toJSONString(this);
    }

    public String getSignString(String appKey,String appSecret){
        String md5String="appKey="+appKey+"&message="+this+appSecret;
        String sign= DigestUtils.md5DigestAsHex(md5String.getBytes());
        return sign;
    }
}
